package com.koron.css2.meterService.impl;


import com.koron.css2.ServerInterface;
import com.koron.css2.meterService.mapper.MsInfoPlanDetailMapper;
import com.koron.css2.meterService.mapper.MsInfoPlanMapper;
import com.koron.css2.serviceManage.bean.RequestBean;
import com.koron.css2.serviceManage.bean.UserInfoBean;
import com.koron.css2.serviceManage.utils.JsonUtils;
import com.koron.util.Constant;
import org.koron.ebs.mybatis.SessionFactory;
import org.swan.bean.MessageBean;

/**
 * 水表入库删除
 * @author bin
 *
 */
public class MsStorageDelete implements ServerInterface{

	@Override
	public MessageBean<?> exec(SessionFactory factory, UserInfoBean userInfo, RequestBean req) {
		
		MessageBean<Void> info = MessageBean.create(Constant.MESSAGE_INT_SUCCESS, "删除成功", Void.class);
		try {
			String id = JsonUtils.objectToPojo(req.getData(), String.class);
			MsInfoPlanMapper msInfoPlanMapper = factory.getMapper(MsInfoPlanMapper.class);
			int iCount = msInfoPlanMapper.deleteById(id);
			if(iCount > 0) {
				MsInfoPlanDetailMapper mapper = factory.getMapper(MsInfoPlanDetailMapper.class);
				mapper.deleteByReceiptId(id);
			}
		} catch (Exception e) {
			info.setCode(Constant.MESSAGE_INT_FAIL);
			info.setDescription("删除失败");
			logger.error(e.getMessage(), e);
		}
		return info;
	}

}
